package com.moody.init;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.moody.hibernate.domain.CodeLib;

/*
 * Copyright © Moody analytics
 *
 * @Author: Yan Jian
 * @Time: 2011-9-22 下午11:21:25
 * @Modified by: 
 * @Description: 获取地址等下拉列表的数据内容,返回List<Map>形式
 */
public class DataLib {

	private static final Logger log = LoggerFactory.getLogger(DataDictionary.class);
	private static DataLib instance = null;

	private DataLib() {

	}

	public static DataLib getInstance() {
		if (instance == null) {
			instance = new DataLib();
		}
		return instance;
	}
	
public  List getListByType(String type){
		
		Map<String, CodeLib> addType = new LinkedHashMap<String, CodeLib>();
		
		addType=DataDictionary.getInstance().getDataDictionary().get(type);
		
		
		List<Map> atl = new ArrayList<Map>();
		Iterator iter = addType.entrySet().iterator(); 
		while (iter.hasNext()) { 
		    Map.Entry entry = (Map.Entry) iter.next(); 
		    String addTypeCode = (String) entry.getKey(); 
		    String addTypeName = ((CodeLib)entry.getValue()).getItemName();
		    String addTypeCodeNo = ((CodeLib)entry.getValue()).getId().getCodeNo();
		    Map<String, String> addTypeMap = new LinkedHashMap<String, String>();
		    //如果是countryCode，只有一位则忽略，如亚洲这样的情况
		    if(type.equals("CountryCode") && addTypeCode.length()==1){
		    }else{	
		    	addTypeMap.put("code", addTypeCode);
		    	addTypeMap.put("name", addTypeName);
		    }
		    //去重，参数管理
		    Boolean flag = true;
		    
//		    if(addTypeCodeNo.endsWith("Param")){
//			    for(Map map : atl){
//			    	if(map.get("name").equals(addTypeName) || map.get("name").equals("0.0")){
//			    		flag = false;
//			    	}
//			    }
//		    }
		    if(flag && addTypeMap.size()>0)
		    	atl.add(addTypeMap);  
		}

		return atl;
	}

}
